import os
 
# 指定目录路径
dir_path = '/Users/zxl/视频/AI人工智能算法教程'

def remove_char(s, char_to_remove):
    return s.replace(char_to_remove, '')

file_count = 0

def rename_files_in_folder(folder_path):
    for filename in os.listdir(folder_path):
        # 构建原文件名和新文件名
        old_file_path = os.path.join(folder_path, filename)
        
        if os.path.isfile(old_file_path):
            otherStr = '_ev【更多资源：微mmj4408】'
            otherStr2 = '【小刀娱乐网www.xiaodao.biz】'
            global file_count
            if old_file_path.__contains__(otherStr):
                new_file_path = remove_char(old_file_path, otherStr)
                # 重命名文件
                os.rename(old_file_path, new_file_path)
                file_count += 1
            elif old_file_path.__contains__(otherStr2):
                new_file_path = remove_char(old_file_path, otherStr2)
                # 重命名文件
                os.rename(old_file_path, new_file_path)
                file_count += 1
        elif os.path.isdir(old_file_path):
            rename_files_in_folder(old_file_path)
 
# 使用函数，假设你想要重命名"my_folder"路径下的文件
rename_files_in_folder(dir_path)

print('修改文件数量：', file_count)